package edu.hubu.talentmanagementsystem.common;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author moonlan
 * date 2021/3/25 上午11:10
 */
@SuppressWarnings(value = "unused")
@Component
public class RedisUtils {

    private final RedisTemplate<String, Object> template;
    private final String isEnabled = "isEnable";
    private final String isForbidden = "isForbidden";

    public RedisUtils(RedisTemplate<String, Object> template) {
        this.template = template;
    }

    public void addToken(String token) {
        template.opsForValue().set(token, isEnabled);
    }

    public boolean isTokenEnable(String token) {
        return Objects.equals(template.opsForValue().get(token), isEnabled);
    }

    public void forbidToken(String token) {
        template.opsForValue().setIfPresent(token, isForbidden);
    }


}
